
use "*/Replication files/anes_timeseries_2016.dta" , clear
drop V160001
rename V160001_orig V160001
merge 1:1 V160001 using "*/Replication files/anes_timeseries_2016_voteval.dta"
svyset [pw= prob_match]

gen satis = V162290
recode satis (-9=.) (-8=.) (-7=.) (-6=.)
recode satis (1=4) (2=3) (4=2) (5=1)

gen racial_resentment1 = V162211
recode racial_resentment1 (-9=.) (-8=.) (-7=.) (-6=.)
revrs racial_resentment1 , replace

gen racial_resentment2 = V162212
recode racial_resentment2 (-9=.) (-8=.) (-7=.) (-6=.)

gen racial_resentment3 = V162213
recode racial_resentment3 (-9=.) (-8=.) (-7=.) (-6=.)

gen racial_resentment4 = V162214
recode racial_resentment4 (-9=.) (-8=.) (-7=.) (-6=.)
revrs racial_resentment4 , replace

corr racial_resentment1 racial_resentment2 racial_resentment3 racial_resentment4 
alpha racial_resentment1 racial_resentment2 racial_resentment3 racial_resentment4 , gen(racial_resentment)

gen vote_post = V161064x
recode vote_post (-1=.) (10 = 1) (11=0) (12=.) (20=1) (21=0) (22=.) (30=.) (31=.) (32=.)
gen winner_post = vote_post
recode winner_post (0=1) (1=0)

gen vote = V162063x
recode vote (-1=.) (10 = 1) (11=0) (12=.) (20=1) (21=0) (22=.) (30=.) (31=.) (32=.)
gen winner = vote
recode winner (0=1) (1=0) (-2=.)

gen income = V161361x
replace income = . if income<1

gen age = V161267
replace age = . if age<18

gen edu =V161270
replace edu = . if edu<1
replace edu = . if edu>90
replace edu = 1 if edu<5
replace edu = 2 if edu<10 & edu>1
replace edu = 2 if edu==90
replace edu = 3 if edu<13 & edu>2
replace edu = 4 if edu>3

gen race = V161310x

gen female = V161342
recode female (-9=.) (1=0) (2=1) (3=.)

gen interest = V161004
revrs interest, replace

gen natl_econ = V161140x
drop if natl_econ <1
revrs natl_econ, replace

gen ideology = V162171
replace ideology = . if ideology<1
replace ideology = . if ideology>7

set more off
* No weighting
ologit satis c.racial_resentment##winner ideology interest natl_econ income age edu female   if race==1 & vote_post==vote & vote2016==1
*	margins , at(racial_resentment=(1(.25)5)) over(winner)
*	marginsplot


*********************************************
* Table 2 and predicted values for Figure 4 * 
*********************************************
svy:  reg satis c.racial_resentment##winner ideology interest natl_econ ///
	income age edu female   if race==1 & vote_post==vote  & vote2016==1
margins , over(winner) at(racial_resentment=(1(.25)5))
	
***************
* Appendicies * 
***************
* Table C.4
svy:  ologit satis c.racial_resentment##winner ideology interest natl_econ ///
	income age edu female   if race==1 & vote_post==vote  & vote2016==1
margins , over(winner) at(racial_resentment=(1(.25)5))
